#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int countArrays(vector<int> &original, vector<vector<int>> &bounds)
    {
        int l = bounds[0][0], r = bounds[0][1];
        int n = original.size();
        for (int i = 1; i < n && r >= l; ++i)
        {
            int del = original[i] - original[i - 1];
            l = max(l + del, bounds[i][0]);
            r = min(r + del, bounds[i][1]);
        }
        return max(0, r - l + 1);
    }
};